﻿using System;
using System.Collections.Generic;
using Hematology.Data;
using Hematology.HmtMembership;
using Hematology.UserSite.Controls;
using NgoResource = Hematology.UserSite.App_GlobalResources.UserSite;

namespace Hematology.UserSite.admin
{
	public partial class GroupManagement : NgoPage
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				FillRolesList();
			}
		}

		private void FillUserList(string sRoleName)
		{
			string[] sRoleMembers = MembershipHelper.RoleService.GetUsersInRole(sRoleName);

			lbGroupUser.DataSource = sRoleMembers;
			lbGroupUser.DataBind();

			lblGroupMembers.Text = String.Format("{0} \"{1}\" [{2}]", NgoResource.resGroupMembers, sRoleName, sRoleMembers.Length);
		}

		private void FillRolesList()
		{
			List<AccessRole> lAccessRoles = AccessRole.GetAllRoles();
			lbGroup.DataSource = lAccessRoles;
			lbGroup.DataBind();
		}

		protected void btnSaveUserRoles_Click(object sender, EventArgs e)
		{

		}

		protected void lbGroup_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (lbGroup.SelectedIndex == -1)
				return;

			FillUserList(lbGroup.SelectedItem.Text);
		}
	}
}